package com.imooc.controller;

import com.imooc.service.SeckillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述: <br>
 * (秒杀-控制层)
 *
 * @Author:Mr. xyb
 * @Date: 2018/5/18 17:32
 * @since: 1.8.0
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/skill")
@Slf4j
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    /**
     * 查询参与秒杀的商品信息
     *
     * @param productId
     * @return 商品信息
     * @throws Exception
     */
    @GetMapping("/query/{productId}")
    public String query(@PathVariable("productId") String productId) throws Exception {
        return seckillService.querySeckillProductInfo(productId);
    }

    /**
     * 进行秒杀
     *
     * @param productId 商品id
     * @return 商品信息
     * @throws Exception
     */
    @GetMapping("/order/{productId}")
    public String skill(@PathVariable String productId) throws Exception {
        log.info("@skill request, productId:" + productId);
        seckillService.orderProductMockDiffUser(productId);
        return seckillService.querySeckillProductInfo(productId);
    }

}
